/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Portions created by the Initial Developer are
 * Copyright (C) 2012 the Initial Developer.
 * All Rights Reserved.
 *
 * The Original Code is "http://semi-frame.googlecode.com/svn/trenk/".
 *
 * The Initial Developer of the Original Code is the author below.
 */
/**
 * @file CurrentTasks.h
 * @brief auto generated.
 * @author mornongcloud
 * @date 2012/10/15
 */

#ifndef SEMICURRENTTASKS_H_
#define SEMICURRENTTASKS_H_

//#include <sys/wait.h>
#include "semi/util/DateUtil.h"
#include "semi/posix/SharedMemory.h"
//#include "semi/conf/TimerConfig.h"

namespace semi {

class CurrentTasks {
public:
	CurrentTasks();
	CurrentTasks(std::string taskName);
	virtual ~CurrentTasks();

	void init(std::string taskName);

	posix::SharedMemory mcrnt;

	std::string taskId;
	int index;

	void setValid(bool val = true); // set task
	bool isValid();

	void setLastTimestamp(long long time);
	void setChildPid(int pid);
	void removeChildPid();
	bool hasChildPid();

	void clear();

	struct CurrentTask {
		char task_id[16]; // id
		char valid; // 1:alive / 0:kill
		int pid;
		int ppid;
		int cpid;
		long long last;
		//		long long next;
	};

	struct CurrentTaskIds {
		CurrentTask task[64];
	};

	static util::Strings getCurrentTaskIds();
	static std::string toString(bool all = false);

private:
	static std::string current_task_file_name;

	static std::string toStringCurrentTask(CurrentTask* crnttsk);
};

}

#endif /* SEMICURRENTTASKS_H_ */
